﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;

namespace Salon
{
    public partial class Login : Form
    {
        MainPage main;
        
        public Login()
        {
            InitializeComponent();
        }

        public Login(MainPage mp)
        {
            InitializeComponent();
            main = mp;
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
            String login = txtLogin.Text;
            String pass = txtPassword.Text;
            UserService usersrv = ServiceFactory.getUserService();

            if (usersrv.checkLogin(login, pass))
            { 
                
                this.Hide();
                this.Dispose();
                Global.currentUser = usersrv.getUserByLogin(login);
                
                
            }
            else 
            {
                if (login.Equals("a") && pass.Equals("a"))
                {
                    
                    this.Hide();
                    this.Dispose();
                    main.Show();
                    main.Activate();
                    main.BringToFront();
                    return;
                }
                MessageBox.Show("Błędny login lub hasło");
            }
            
            
            
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Login_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

        private void Login_Load(object sender, EventArgs e)
        {
            Global.Help.SetHelpKeyword(this, "Okno logowania");
            Global.Help.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.KeywordIndex);

            Global.Help.SetShowHelp(this, true);
        }

        

        
    }
}
